package desmontec.documentos;

import grails.test.*

class GuiaDeTrafegoTests extends GrailsUnitTestCase {

	def guiaDeTrafego = new GuiaDeTrafego()
	
    protected void setUp() {
        super.setUp()
		mockForConstraintsTests(GuiaDeTrafego, [guiaDeTrafego])
    }

    protected void tearDown() {
        super.tearDown()
    }

   
	void testGuiaParametrosNull(){

		def guia1 = new GuiaDeTrafego(numeroDaGuia:null, dinamite: null, espoleta: null,estopim: null,
				cordelDet: null, espoletim: null, retardo: null)

		assertFalse(guia1.validate())

		assertEquals "nullable", guia1.errors["numeroDaGuia"]
		assertEquals "nullable", guia1.errors["dinamite"]
		assertEquals "nullable", guia1.errors["espoleta"]
		assertEquals "nullable", guia1.errors["espoleta"]
		assertEquals "nullable", guia1.errors["estopim"]
		assertEquals "nullable", guia1.errors["cordelDet"]
		assertEquals "nullable", guia1.errors["espoletim"]
		assertEquals "nullable", guia1.errors["retardo"]
	}

	void testGuiaValorMinimoParametros(){

		def guia1 = new GuiaDeTrafego(numeroDaGuia:1234569, dinamite: -1, espoleta: -1,estopim: -1,
				cordelDet: -1, espoletim: -1, retardo: -1)

		assertFalse(guia1.validate())

		assertEquals "min", guia1.errors["dinamite"]
		assertEquals "min", guia1.errors["espoleta"]
		assertEquals "min", guia1.errors["espoleta"]
		assertEquals "min", guia1.errors["estopim"]
		assertEquals "min", guia1.errors["cordelDet"]
		assertEquals "min", guia1.errors["espoletim"]
		assertEquals "min", guia1.errors["retardo"]
	}
	
	void testNumeroGuiaValorUnico(){
		def guia1 = new GuiaDeTrafego(numeroDaGuia:1234569, dinamite: 1, espoleta: 1,estopim: 1,
			cordelDet: 1, espoletim: 1, retardo: 1)
		mockForConstraintsTests(GuiaDeTrafego, [guia1]);

		
		def guia2 = new GuiaDeTrafego(numeroDaGuia:1234569, dinamite: 1, espoleta: 1,estopim: 1,
			cordelDet: 1, espoletim: 1, retardo: 1)
		
		assertFalse guia2.validate()
		assertEquals "unique", guia2.errors["numeroDaGuia"]
		
	}
}
